package logic

import (
	"context"
	"fmt"
	"house_srv/model/mysql"

	"house_srv/internal/svc"
	"house_srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseInfoLogic {
	return &HouseInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *HouseInfoLogic) HouseInfo(in *srv.HouseInfoRequest) (*srv.HouseInfoResponse, error) {
	// todo: add your logic here and delete this line

	var house mysql.House
	mysql.DB.Debug().Where("id = ?", in.Id).Find(&house)
	if house.ID == 0 {
		return nil, fmt.Errorf("商品不存在，不能查看详情")
	}
	return &srv.HouseInfoResponse{
		Name:    house.Name,
		Address: house.Address,
		Area:    house.Area,
		Price:   float32(house.Price),
		Image:   house.Image,
		Id:      int64(house.ID),
	}, nil
}
